<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <script>
    // for await...of 语句会在异步或者同步可迭代对象上创建一个迭代循环
    // 循环异步对象
    function gen(time) {
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve(time)
        }, time)
      })
    }

    // for of循环异步对象 for循环结束统一返回结果
    //for await of 异步对象执行结束返回  结合async使用
    async function test() {
      let arr = [gen(2000), gen(5000), gen(3000)]
      for await (let x of arr) {
        console.log(Date.now(), x)
      }
    }
    test() 
  </script>
</body>

</html>